home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Documentation / d e v e l o p / Develop Issue 23 article / Geometry Sample / QD3D src / MainWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-21  |  3.8 KB  |  162 lines  |  [TEXT/MPCC]

  1.  
  2. #include "QD3D.h"
  3. #include "QD3DMath.h"
  4.  
  5. #include "DragSupport.h"
  6. #include "WindowObj.h"
  7.  
  8. #include "QuickDraw3DSupport.h"
  9. #include "MainWindow.h"
  10.  
  11.  
  12.  
  13.  
  14. //-----------------------------------------------------------------------
  15. // •• MAIN WINDOW ••
  16. //-----------------------------------------------------------------------
  17. static void MainWindowCreate(WindowObjHndl);
  18. static void MainWindowIdle(WindowObjHndl);
  19.  
  20.  
  21. //-----------------------------------------------------------------------
  22.  
  23. Boolean Is3DWindow(WindowPtr win)
  24. {
  25.     WindowObjHndl    obj;
  26.     Boolean            is3DWindow;
  27.     
  28.     is3DWindow = false;
  29.     
  30.     if (win != NULL) {
  31.         obj = (WindowObjHndl) GetWRefCon(win);
  32.         is3DWindow = ((*obj)->type == 'Main');
  33.     }
  34.  
  35.     return is3DWindow;
  36. }
  37.  
  38. //-----------------------------------------------------------------------
  39.  
  40. void MainWindowNotify(WindowObjHndl obj, long message)
  41. {
  42.     switch (message) {
  43.         case kCreateNotification:
  44.             MainWindowCreate(obj);
  45.             break;
  46.             
  47.         case kCloseNotification:
  48.             DisposeObjWindow(obj);
  49.             break;
  50.         
  51.         case kAdjustMenusNotification: {
  52.                 MenuHandle     fileMenu = GetMenuHandle(kFileMenu);
  53.                 MenuHandle     editMenu = GetMenuHandle(kEditMenu);
  54.             
  55.                 if (fileMenu != NULL) {
  56.                     EnableItem(fileMenu, kNewItem);        
  57.                     EnableItem(fileMenu, kOpenItem);
  58.                     EnableItem(fileMenu, kCloseItem);
  59.                     EnableItem(fileMenu, kQuitItem);
  60.                 }
  61.                 
  62.                 if (editMenu != NULL) {                    
  63.                     DisableItem(editMenu, kUndoItem);
  64.                     DisableItem(editMenu, kCutItem);
  65.                     DisableItem(editMenu, kCopyItem);
  66.                     DisableItem(editMenu, kPasteItem);
  67.                     DisableItem(editMenu, kClearItem);
  68.                     DisableItem(editMenu, kSelectAllItem);
  69.                 }
  70.             }
  71.             break;
  72.         
  73.         case kDestroyNotification:
  74.             RemoveDragHandlers((*obj)->window);
  75.             break;
  76.         
  77.         case kIdleNotification:
  78.             MainWindowIdle(obj);
  79.             break;
  80.     }
  81. }
  82.  
  83. //-----------------------------------------------------------------------
  84.  
  85. void MainWindowKeys(WindowObjHndl obj, long message, short mods)
  86. {
  87. #pragma unused (obj, message, mods)
  88.     SysBeep(20);
  89. }
  90.  
  91. //-----------------------------------------------------------------------
  92.  
  93. void MainWindowClick(WindowObjHndl obj, EventRecord *event, long message)
  94. {
  95. #pragma unused (obj, message, event)
  96. }
  97.  
  98. //-----------------------------------------------------------------------
  99.  
  100. void MainWindowDraw(WindowObjHndl obj, short depth)
  101. {
  102. #pragma unused (depth)
  103.     WindowPtr        win = (*obj)->window;
  104.     DocumentHdl        theDocument;
  105.     
  106.     theDocument = GetDocumentHdl(obj);
  107.     
  108.     if ((theDocument != NULL) && (**theDocument).fModel != NULL) {
  109.         HLock((Handle) theDocument);
  110.         Q3View_StartRendering((**theDocument).fView) ;
  111.         do {
  112.             (void) SubmitScene(theDocument) ;
  113.         } while (Q3View_EndRendering((**theDocument).fView) == kQ3ViewStatusRetraverse);
  114.     
  115.         HUnlock((Handle) theDocument);
  116.     }
  117. }
  118.  
  119. //-----------------------------------------------------------------------
  120. // we received a null event, rotate the object if there is one.
  121. //-----------------------------------------------------------------------
  122. static void MainWindowIdle(WindowObjHndl obj)
  123. {
  124.     WindowPtr        win = (*obj)->window;
  125.     TQ3Matrix4x4    tmp;
  126.     Rect            theRect;
  127.     DocumentHdl        theDocument;
  128.  
  129.     theDocument = GetDocumentHdl(obj) ;
  130.  
  131.     if (theDocument != NULL) {
  132.         theRect = win->portRect;
  133.         Q3Matrix4x4_SetRotate_XYZ(&tmp, 0.05, 0.06, 0.08);
  134.         HLock((Handle) theDocument);
  135.         Q3Matrix4x4_Multiply(&(**theDocument).fRotation, &tmp, &(**theDocument).fRotation);
  136.         HUnlock((Handle) theDocument);
  137.         InvalRect(&theRect);
  138.     }
  139. }
  140.  
  141. //-----------------------------------------------------------------------
  142.  
  143. static void MainWindowCreate(WindowObjHndl obj)
  144. {
  145.     DocumentHdl    doc;
  146.     
  147.     doc = CreateDocument((*obj)->window);
  148.     require(doc != NULL, CreateDocumentFailed);
  149.  
  150.     TextFont(monaco);
  151.     TextSize(9);
  152.  
  153.     (*obj)->refCon = (unsigned long) doc;
  154.  
  155.     if (InstallDragHandlers((*obj)->window) != noErr)
  156.         DebugStr("\pDrag handler installation failed.");
  157.  
  158. //    SetWindowGeometry((*obj)->window, 1);
  159.  
  160. CreateDocumentFailed:
  161.     return;
  162. }